package com.diyunapp.xilinapp.me;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.diyunapp.xilinapp.R;
import com.diyunapp.xilinapp.main.MainActivity;
import com.diyunapp.xilinapp.selfdefine.StatusBarFragmentActivity;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.RequestParams;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest;

import org.json.JSONException;
import org.json.JSONObject;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class SurveyActivity extends StatusBarFragmentActivity {

    @Bind(R.id.go_back1)
    ImageView goBack1;
    @Bind(R.id.dear_tv)
    TextView dearTv;
    @Bind(R.id.login_tv)
    TextView loginTv;
    @Bind(R.id.very_good1)
    RadioButton veryGood1;
    @Bind(R.id.good1)
    RadioButton good1;
    @Bind(R.id.little_good1)
    RadioButton littleGood1;
    @Bind(R.id.bad_1)
    RadioButton bad1;
    @Bind(R.id.very_bad1)
    RadioButton veryBad1;
    @Bind(R.id.radiogroup1)
    RadioGroup radiogroup1;
    @Bind(R.id.very_good2)
    RadioButton veryGood2;
    @Bind(R.id.good2)
    RadioButton good2;
    @Bind(R.id.little_good2)
    RadioButton littleGood2;
    @Bind(R.id.bad_2)
    RadioButton bad2;
    @Bind(R.id.very_bad2)
    RadioButton veryBad2;
    @Bind(R.id.radiogroup2)
    RadioGroup radiogroup2;
    @Bind(R.id.very_good3)
    RadioButton veryGood3;
    @Bind(R.id.good3)
    RadioButton good3;
    @Bind(R.id.little_good3)
    RadioButton littleGood3;
    @Bind(R.id.bad_3)
    RadioButton bad3;
    @Bind(R.id.very_bad3)
    RadioButton veryBad3;
    @Bind(R.id.radiogroup3)
    RadioGroup radiogroup3;
    @Bind(R.id.very_good4)
    RadioButton veryGood4;
    @Bind(R.id.good4)
    RadioButton good4;
    @Bind(R.id.little_good4)
    RadioButton littleGood4;
    @Bind(R.id.bad_4)
    RadioButton bad4;
    @Bind(R.id.very_bad4)
    RadioButton veryBad4;
    @Bind(R.id.radiogroup4)
    RadioGroup radiogroup4;
    @Bind(R.id.very_good5)
    RadioButton veryGood5;
    @Bind(R.id.good5)
    RadioButton good5;
    @Bind(R.id.little_good5)
    RadioButton littleGood5;
    @Bind(R.id.bad_5)
    RadioButton bad5;
    @Bind(R.id.very_bad5)
    RadioButton veryBad5;
    @Bind(R.id.radiogroup5)
    RadioGroup radiogroup5;
    @Bind(R.id.very_good6)
    RadioButton veryGood6;
    @Bind(R.id.good6)
    RadioButton good6;
    @Bind(R.id.little_good6)
    RadioButton littleGood6;
    @Bind(R.id.bad_6)
    RadioButton bad6;
    @Bind(R.id.very_bad6)
    RadioButton veryBad6;
    @Bind(R.id.radiogroup6)
    RadioGroup radiogroup6;
    @Bind(R.id.very_good7)
    RadioButton veryGood7;
    @Bind(R.id.good7)
    RadioButton good7;
    @Bind(R.id.little_good7)
    RadioButton littleGood7;
    @Bind(R.id.bad_7)
    RadioButton bad7;
    @Bind(R.id.very_bad7)
    RadioButton veryBad7;
    @Bind(R.id.radiogroup7)
    RadioGroup radiogroup7;
    @Bind(R.id.very_good8)
    RadioButton veryGood8;
    @Bind(R.id.good8)
    RadioButton good8;
    @Bind(R.id.little_good8)
    RadioButton littleGood8;
    @Bind(R.id.bad_8)
    RadioButton bad8;
    @Bind(R.id.very_bad8)
    RadioButton veryBad8;
    @Bind(R.id.radiogroup8)
    RadioGroup radiogroup8;
    @Bind(R.id.very_good9)
    RadioButton veryGood9;
    @Bind(R.id.good9)
    RadioButton good9;
    @Bind(R.id.little_good9)
    RadioButton littleGood9;
    @Bind(R.id.bad_9)
    RadioButton bad9;
    @Bind(R.id.very_bad9)
    RadioButton veryBad9;
    @Bind(R.id.radiogroup9)
    RadioGroup radiogroup9;
    @Bind(R.id.very_good10)
    RadioButton veryGood10;
    @Bind(R.id.good10)
    RadioButton good10;
    @Bind(R.id.little_good10)
    RadioButton littleGood10;
    @Bind(R.id.bad_10)
    RadioButton bad10;
    @Bind(R.id.very_bad10)
    RadioButton veryBad10;
    @Bind(R.id.radiogroup10)
    RadioGroup radiogroup10;
    @Bind(R.id.very_good11)
    RadioButton veryGood11;
    @Bind(R.id.good11)
    RadioButton good11;
    @Bind(R.id.little_good11)
    RadioButton littleGood11;
    @Bind(R.id.bad_11)
    RadioButton bad11;
    @Bind(R.id.very_bad11)
    RadioButton veryBad11;
    @Bind(R.id.radiogroup11)
    RadioGroup radiogroup11;
    @Bind(R.id.very_good12)
    RadioButton veryGood12;
    @Bind(R.id.good12)
    RadioButton good12;
    @Bind(R.id.little_good12)
    RadioButton littleGood12;
    @Bind(R.id.bad_12)
    RadioButton bad12;
    @Bind(R.id.very_bad12)
    RadioButton veryBad12;
    @Bind(R.id.radiogroup12)
    RadioGroup radiogroup12;
    @Bind(R.id.very_good13)
    RadioButton veryGood13;
    @Bind(R.id.good13)
    RadioButton good13;
    @Bind(R.id.little_good13)
    RadioButton littleGood13;
    @Bind(R.id.bad_13)
    RadioButton bad13;
    @Bind(R.id.very_bad13)
    RadioButton veryBad13;
    @Bind(R.id.radiogroup13)
    RadioGroup radiogroup13;
    @Bind(R.id.phone_edt)
    EditText phoneEdt;
    @Bind(R.id.question_edt)
    EditText questionEdt;
    public String fcmy="非常满意";
    public String my="满意";
    public String ybmy="一般满意";
    public String bmy="不满意";
    public String hcbmy="非常不满意";
    public String wt1;
    public String wt2;
    public String wt3;
    public String wt4;
    public String wt5;
    public String wt6;
    public String wt7;
    public String wt8;
    public String wt9;
    public String wt10;
    public String wt11;
    public String wt12;
    public String wt13;
    public String wt14;
    public String wt15;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_survey);
        ButterKnife.bind(this);
        View headView;
        headView = findViewById(R.id.survey_menubar_inc);
        super.MenuWidget(headView);
        dearTv.setText("亲爱的用户：\n" +
                "您对希霖网商城有任何意见和建议，或在使用过程中遇到问题，请在本页面反馈。" +
                "我们会每天关注您的反馈，不断优化产品，为您提供更好的服务！");
        initView();
    }

    private void initView() {
        radiogroup1.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                // TODO Auto-generated method stub
                if(checkedId==veryGood1.getId()) {
                    wt1=fcmy;
                }else if(checkedId==good1.getId()) {
                wt1=my;
                }else if(checkedId== littleGood1.getId()){
                    wt1=ybmy;
                }else if(checkedId== bad1.getId()){
                    wt1=bmy;
                }else if(checkedId==veryBad1.getId()){
                    wt1=hcbmy;
                }
            }
        });
        radiogroup2.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                // TODO Auto-generated method stub
                if(checkedId==veryGood2.getId()) {
                    wt2=fcmy;
                }else if(checkedId==good2.getId()) {
                    wt2=my;
                }else if(checkedId== littleGood2.getId()){
                    wt2=ybmy;
                }else if(checkedId== bad2.getId()){
                    wt2=bmy;
                }else if(checkedId==veryBad2.getId()){
                    wt2=hcbmy;
                }
            }
        });
        radiogroup3.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                // TODO Auto-generated method stub
                if(checkedId==veryGood3.getId()) {
                    wt3=fcmy;
                }else if(checkedId==good3.getId()) {
                    wt3=my;
                }else if(checkedId== littleGood3.getId()){
                    wt3=ybmy;
                }else if(checkedId== bad3.getId()){
                    wt3=bmy;
                }else if(checkedId==veryBad3.getId()){
                    wt3=hcbmy;
                }
            }
        });
        radiogroup4.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                // TODO Auto-generated method stub
                if(checkedId==veryGood4.getId()) {
                    wt4=fcmy;
                }else if(checkedId==good4.getId()) {
                    wt4=my;
                }else if(checkedId== littleGood4.getId()){
                    wt4=ybmy;
                }else if(checkedId== bad4.getId()){
                    wt4=bmy;
                }else if(checkedId==veryBad4.getId()){
                    wt4=hcbmy;
                }
            }
        });
        radiogroup5.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                // TODO Auto-generated method stub
                if(checkedId==veryGood5.getId()) {
                    wt5=fcmy;
                }else if(checkedId==good5.getId()) {
                    wt5=my;
                }else if(checkedId== littleGood5.getId()){
                    wt5=ybmy;
                }else if(checkedId== bad5.getId()){
                    wt5=bmy;
                }else if(checkedId==veryBad5.getId()){
                    wt5=hcbmy;
                }
            }
        });
        radiogroup6.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                // TODO Auto-generated method stub
                if(checkedId==veryGood6.getId()) {
                    wt6=fcmy;
                }else if(checkedId==good6.getId()) {
                    wt6=my;
                }else if(checkedId== littleGood6.getId()){
                    wt6=ybmy;
                }else if(checkedId== bad6.getId()){
                    wt6=bmy;
                }else if(checkedId==veryBad6.getId()){
                    wt6=hcbmy;
                }
            }
        });
        radiogroup7.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                // TODO Auto-generated method stub
                if(checkedId==veryGood7.getId()) {
                    wt7=fcmy;
                }else if(checkedId==good7.getId()) {
                    wt7=my;
                }else if(checkedId== littleGood7.getId()){
                    wt7=ybmy;
                }else if(checkedId== bad7.getId()){
                    wt7=bmy;
                }else if(checkedId==veryBad7.getId()){
                    wt7=hcbmy;
                }
            }
        });
        radiogroup8.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                // TODO Auto-generated method stub
                if(checkedId==veryGood8.getId()) {
                    wt2=fcmy;
                }else if(checkedId==good8.getId()) {
                    wt8=my;
                }else if(checkedId== littleGood8.getId()){
                    wt8=ybmy;
                }else if(checkedId== bad8.getId()){
                    wt8=bmy;
                }else if(checkedId==veryBad8.getId()){
                    wt8=hcbmy;
                }
            }
        });
        radiogroup9.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                // TODO Auto-generated method stub
                if(checkedId==veryGood9.getId()) {
                    wt9=fcmy;
                }else if(checkedId==good9.getId()) {
                    wt9=my;
                }else if(checkedId== littleGood9.getId()){
                    wt9=ybmy;
                }else if(checkedId== bad9.getId()){
                    wt9=bmy;
                }else if(checkedId==veryBad9.getId()){
                    wt9=hcbmy;
                }
            }
        });
        radiogroup10.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                // TODO Auto-generated method stub
                if(checkedId==veryGood10.getId()) {
                    wt10=fcmy;
                }else if(checkedId==good10.getId()) {
                    wt10=my;
                }else if(checkedId== littleGood10.getId()){
                    wt10=ybmy;
                }else if(checkedId== bad10.getId()){
                    wt10=bmy;
                }else if(checkedId==veryBad10.getId()){
                    wt10=hcbmy;
                }
            }
        });
        radiogroup11.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                // TODO Auto-generated method stub
                if(checkedId==veryGood11.getId()) {
                    wt11=fcmy;
                }else if(checkedId==good11.getId()) {
                    wt11=my;
                }else if(checkedId== littleGood11.getId()){
                    wt11=ybmy;
                }else if(checkedId== bad11.getId()){
                    wt11=bmy;
                }else if(checkedId==veryBad11.getId()){
                    wt11=hcbmy;
                }
            }
        });
        radiogroup12.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                // TODO Auto-generated method stub
                if(checkedId==veryGood12.getId()) {
                    wt12=fcmy;
                }else if(checkedId==good12.getId()) {
                    wt12=my;
                }else if(checkedId== littleGood12.getId()){
                    wt12=ybmy;
                }else if(checkedId== bad12.getId()){
                    wt12=bmy;
                }else if(checkedId==veryBad12.getId()){
                    wt12=hcbmy;
                }
            }
        });
        radiogroup13.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                // TODO Auto-generated method stub
                if(checkedId==veryGood13.getId()) {
                    wt13="纯买家";
                }else if(checkedId==good13.getId()) {
                    wt13="既是买家也是卖家";
                }else if(checkedId== littleGood13.getId()){
                    wt13="纯卖家";
                }else if(checkedId== bad13.getId()){
                    wt13="代理商";
                }else if(checkedId==veryBad13.getId()){
                    wt13="都不是";
                }
            }
        });

    }


    @OnClick({R.id.go_back1, R.id.login_tv})
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.go_back1:
                finish();
                break;
            case R.id.login_tv:
                doCommit();
                break;
        }
    }

    private void doCommit() {
        wt14=phoneEdt.getText().toString().trim();
        wt15=questionEdt.getText().toString().trim();
        String url = "" + MainActivity.url + "act=goods&op=wjdc";
        RequestParams params = new RequestParams();
        params.addBodyParameter("member_id", MainActivity.myLogin.getMemberid());
        params.addBodyParameter("member_name",  MainActivity.myLogin.getUsername());
        params.addBodyParameter("wt1",wt1);
        params.addBodyParameter("wt2",wt2);
        params.addBodyParameter("wt3",wt3);
        params.addBodyParameter("wt4",wt4);
        params.addBodyParameter("wt5",wt5);
        params.addBodyParameter("wt6",wt6);
        params.addBodyParameter("wt7",wt7);
        params.addBodyParameter("wt8",wt8);
        params.addBodyParameter("wt9",wt9);
        params.addBodyParameter("wt10",wt10);
        params.addBodyParameter("wt11",wt11);
        params.addBodyParameter("wt12",wt12);
        params.addBodyParameter("wt13",wt13);
        params.addBodyParameter("wt14",wt14);
        params.addBodyParameter("wt15",wt15);

        String wt = wt1+"+2"+wt2+"+3"+wt3+"+4"+wt4+"+5"+wt5+"+6"+wt6+"+7"+wt7+"+8"+wt8+"+9"+wt9+"+10"+wt10
                +"+11"+wt11+"+12"+wt12+"+13"+wt13+"+14"+wt14+"+15"+wt15;
        Log.i("xiaogaladebug",wt);
        Log.i("xiaogaladebug", String.valueOf(params));
        HttpUtils http = new HttpUtils();
        http.configCurrentHttpCacheExpiry(1000);
        http.send(HttpRequest.HttpMethod.POST, url,params,
                new RequestCallBack<String>() {
                    @Override
                    public void onLoading(long total, long current, boolean isUploading) {

                    }

                    @Override
                    public void onSuccess(ResponseInfo<String> responseInfo) {
                        String resultinfo = responseInfo.result;
                        Log.i("zhangxiaoxidebug", "resultinfo=" + resultinfo);
                        try {
                            JSONObject resultObject = new JSONObject(resultinfo);
                            int result = resultObject.optInt("code");
                            String data = resultObject.optString("data");
                            toast(data);
                            finish();

                        } catch (JSONException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                    }

                    @Override
                    public void onFailure(HttpException error, String msg) {
                        toast("请求失败");
                    }
                });
    }

}
